package com.hanserwei.community.exception;

import com.hanserwei.community.enums.ResponseCodeEnum;
import lombok.Getter;

/**
 * 业务自定义异常类
 * 用于在业务层抛出，统一由全局异常处理器捕获处理
 */
public class ApiException extends RuntimeException {

    @Getter
    private final ResponseCodeEnum responseCode;
    private final String message;

    public ApiException(ResponseCodeEnum responseCode) {
        super(responseCode.getMessage());
        this.responseCode = responseCode;
        this.message = responseCode.getMessage();
    }

    public ApiException(ResponseCodeEnum responseCode, String message) {
        super(message);
        this.responseCode = responseCode;
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }
}